// initMetrologyLib.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "mex.h"
#include <MetrologySystems.h> 


void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{ 
	/************************************************************
	* Mit Metrology-Lib initialisieren, damit der Blitzcontroller
	* korrekt konfiguriert wird.
	************************************************************/
	int n = 0;
	
	if (nrhs > 0) {
		n = (int) mxGetPr(prhs[0])[0];
	}
	
	printf("Creating MetrologySystems object.\n");
	
	metro_lib::MetrologySystems ms;
	
	metro_lib::MeasurementSystemInfoList msil = ms.FindMeasurementSystems();
	printf("MeasurementSystemInfoList has %d entries.\n", msil.Size());
	
	
	if ((n < 0) || (n >= msil.Size())) {
		printf("%d is not a valid system configuration.\n", n);
		printf("Valid configurations range from 0 to %d.\n", msil.Size()-1);
		
		return;
	}
	printf("Initialising MeasurementSystem %d.\n", n);
	
	ms.InitSystem(msil.GetElement(n));
	
	printf("Releasing MeasurementSystem.\n");
	
	ms.~MetrologySystems();
	
	
	/************************************************************
	* Ende Metrology-Lib
	************************************************************/

}